home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.014.FontReport / fontreport.c next >
Encoding:
C/C++ Source or Header  |  1990-06-24  |  44.5 KB  |  1,247 lines  |  [TEXT/MPS ]

  1. #define productionVersion 1
  2.  
  3. /* *************************************************************************** */
  4. /*                                                                               */
  5. /* Font Manager Sample Program                                                   */
  6. /*                                                                               */
  7. /* Description: Produces and displays catalog of fonts on disk, shows            */
  8. /*                font strike of selected font.                                   */
  9. /*                                                                             */
  10. /* Developer Technical Support Apple II Sample Code                            */
  11. /*                                                                             */
  12. /* By: Dan Strnad                                                               */
  13. /*                                                                               */
  14. /*       Version 3.0                                                               */
  15. /*                                                                               */
  16. /* ShowFont Procedure adapted from HodgePodge example program                    */
  17. /*                                                                               */
  18. /* Copyright 1989-1990 Apple Computer, Inc.                                       */
  19. /*                                                                               */
  20. /* *************************************************************************** */
  21.  
  22. /* **************************************************************************** */
  23. /*                                                                                */
  24. /* General Remarks                                                                 */
  25. /*                                                                                */
  26. /* Most applications need not use each of the Font Manager calls demonstrated   */
  27. /* in this program. Besides starting up and shutting down the font manager,     */                                                                         
  28. /* ChooseFont and GetFamNum are the calls most programmers may find use for.    */                                                                         
  29. /* QuickDraw II also provides routines and documentation for both basic and     */
  30. /* advanced handling of fonts.                                                    */
  31. /*                                                                                */
  32. /* Because memory management strategies differ across applications, no special  */
  33. /* provision is made in this program for handling memory error conditions such  */
  34. /* as an unable to allocate memory block error ($0201). This or other memory    */
  35. /* manager errors can be returned by several of the font manager calls. This     */
  36. /* sample program is incomplete with regard to handling of these errors, which  */
  37. /* will cause an error message to be displayed and the program to abort.        */
  38. /* Commercial applications should differ from this sample program by more        */
  39. /* carefully handling potentially tight memory conditions.                        */
  40. /*                                                                                */
  41. /* Also to do with memory management, when fonts are to be marked purgeable     */
  42. /* using SetPurgeStat, the id of the font to purge should be that returned from */
  43. /* a font manager call, such as FMGetCurFID, FindFontStats, or LoadFont.        */
  44. /*                                                                                */
  45. /* The following statements contradict and supercede related information        */
  46. /* about font family numbers in the 1988 Apple IIGS Toolbox Reference Manual:   */
  47. /* Always determine the famNum part of a font id using font manager calls.         */
  48. /* The family number for a font family known by a particular name may differ    */
  49. /* each time the font manager is started!                                        */
  50. /* Do not use statements like 'MyFontID.famNum = 22;' to select the Courier     */
  51. /* font family, for instance.                                                    */
  52. /*                                                                                */
  53. /* Use GetFamNum to determine the font family number for a particularly named   */                                    
  54. /* font family. See the AddApFont routine for an example of calling GetFamNum.  */
  55. /*                                                                                */
  56. /* ***************************************************************************  */
  57.  
  58.  
  59. #include <types.h>     
  60. #include <prodos.h>                             
  61. #include <misctool.h>                            
  62. #include <quickdraw.h>                         
  63. #include <window.h>
  64. #include <memory.h>
  65. #include <dialog.h>
  66. #include <menu.h>
  67. #include <control.h>
  68. #include <desk.h>
  69. #include <event.h>
  70. #include <lineedit.h>
  71. #include <misctool.h>
  72. #include <locator.h>
  73. #include <Stdfile.h>
  74. #include <qdaux.h>
  75. #include <print.h>
  76. #include <font.h>
  77. #include <intmath.h>
  78. #include <scrap.h>
  79. #include <texttool.h>
  80. #include <list.h>
  81. #include <Math.h>
  82. #include <Resources.h>
  83.  
  84. extern int _toolErr;
  85.  
  86. #if productionVersion
  87. #define initPtrCheck(x);
  88. #define closePtrCheck();
  89. #define zapLocals();
  90. #define checkForHit();
  91. #endif
  92.  
  93. /* ************************************************************************* */
  94. /*                                                                             */
  95. /* Standard Global data here                                                 */
  96. /*                                                                             */
  97. /* ************************************************************************* */
  98.  
  99. #define ScreenWidth 640
  100.  
  101. int MyID;
  102. int ThisMode = mode640;                           /* init mode = 640 */
  103.  
  104. Ref initRef;                        /* This holds the reference to the startstop record */
  105.  
  106. int QuitFlag;
  107. QuitRec QuitParms = {
  108.         NULL,                        /* Pathname of the next application */
  109.         0};                            /* Quit Flags */
  110.         
  111. WmTaskRec EventRec = {                /* Data block to hold event records */
  112.         0,
  113.         0L,
  114.         0L,
  115.         0,0,
  116.         0,
  117.         0L,
  118.         0x0000FFFFL};                /* Let TaskMaster do it all! */
  119.  
  120.  
  121. /* ************************************************************************* */
  122. /*                                                                             */
  123. /* ErrorCheck - Called from InitTools to check for startup errors.             */
  124. /*                                                                             */
  125. /* ************************************************************************* */
  126.  
  127. char DeathMsg[] = "Fatal error $0000 has occurred at 0000. Press any key to exit:";
  128.  
  129. void ErrorCheck(where)
  130.     int where;
  131. {
  132.     if (_toolErr) {
  133.         Int2Hex(_toolErr,DeathMsg + 13 ,4);    /* Stick error # into a string */
  134.         Int2Hex(where,DeathMsg + 34 ,4);        /* Stick location # into a string */
  135.         GrafOff();                            /* Turn off Super Hires */
  136.         WriteCString(DeathMsg);                /* Print the error message */
  137.         ReadChar(0);                            /* Pause for a character */
  138.         ShutDownTools(refIsHandle, initRef);    /* Let the toolbox shutdown the tools. */
  139.         exit(1);                                /* exit */
  140.     }
  141. }
  142.  
  143.  
  144. /* ************************************************************************* */
  145. /*                                                                             */
  146. /* ApErrorCheck - Called to check for tool and other miscellaneous errors.     */
  147. /*                                                                             */
  148. /* ************************************************************************* */
  149.  
  150. char ApErrMsg[] = "Appl. error $0000 has occurred at 0000. Press any key to exit:";
  151.  
  152. void ApErrorCheck(where)
  153. int where;
  154. {
  155.     int My_toolErr;
  156.  
  157.     zapLocals();
  158.  
  159.     My_toolErr = _toolErr;
  160.     if (_toolErr) {
  161.         Int2Hex(_toolErr,ApErrMsg + 13 ,4);        /* Stick error # into a string */
  162.         Int2Hex(where,ApErrMsg + 34 ,4);        /* Stick location # into a string */
  163.         GrafOff();                                /* Turn off Super Hires */
  164.         WriteCString(ApErrMsg);                    /* Print the error message */
  165.         ReadChar(0);                            /* Pause for a character */
  166.         if ((My_toolErr & 0xFF00) == 0x200 )     /* abort sample application if memory manager error */
  167.         {
  168.             ShutDownTools(refIsHandle, initRef);    /* Let the toolbox shutdown the tools. */
  169.             exit(1);                                /* exit */
  170.         }
  171.         GrafOn();                                /* Turn on Super Hires */
  172.     }
  173. }
  174.  
  175.  
  176. /* ************************************************************************* */
  177. /*                                                                             */
  178. /* Application specific data appears here                                     */
  179. /*                                                                             */
  180. /* ************************************************************************* */
  181.  
  182. #define TLStartErr                        1
  183. #define ShowFontInstallFontErr            2
  184. #define MyDrawLoadSysFontErr            3
  185. #define MyDraw2LoadSysFontErr            4
  186. #define ApFontNewHandleErr                5
  187. #define ApFontAddFamilyErr                6
  188. #define ApFontAddFontVarErr                7
  189. #define ApFontInstallFontErr1            8
  190. #define ApFontInstallFontErr2            9
  191. #define InvFontLoadSysFontErr            10
  192. #define InvFontLoadFontErr                11
  193. #define InvFontSetPurgeStatErr            12
  194. #define DispNewFontInstallFontErr        13
  195. #define FindAltSysFontFMSetSysFontErr    14
  196. #define MenuFontChooseErr                15
  197. #define InitAppInstallFontErr            16
  198.  
  199. #define NumExampleLines 5                    /* used by ShowFont    */
  200. #define NumStrikeLines 8                    /* used by ShowFont    */
  201. #define ScalingOn    0                        /* used calling InstallFont */
  202. #define IllegalFontFamNum 0xffff            /* used by AddApFont */
  203. #define Hex 16                                /* used calling DrawCatInt2Base */
  204. #define Dec 10                                /* used calling DrawCatInt2Base */
  205. #define signednum true                        /* used calling DrawCatInt2Base */
  206. #define loadfonts true                        /* used calling InventoryFonts */
  207. #define dontloadfonts false                    /* used calling InventoryFonts */
  208. #define douncheck true                        /* used calling FontCheckMItem */
  209. #define omituncheck false                    /* used calling FontCheckMItem */
  210.  
  211. #define CatalogWindowID        0x1000L
  212. #define StrikeWindowID        0x1001L
  213.  
  214. /* *************************************************************************  */
  215. /*
  216. /* This sample program uses menu items that start at 250. The Edit menu items */
  217. /* if they were present would be entered first to conform to the menu manager */
  218. /* documentation. The About and Quit menu items use IDs 256 and 257 as a      */
  219. /* convention.                                                                   */
  220. /*                                                                              */
  221. /* *************************************************************************  */
  222.  
  223. #define AppleMenuID            0x1100
  224. #define AboutID                0x1101
  225. #define FileMenuID            0x1200
  226. #define OpenCatWindowID        0x1201
  227. #define OpenStrikeWindowID    0x1202
  228. #define QuitID                257
  229. #define FontMenuID            0x1300
  230. #define ChooseID            0x1301
  231.  
  232.  
  233. int CurrHeight,LineCounter;
  234.  
  235. char Line0[30] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /*   Namelength + 1  */
  236.                   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; /* + 4 for size info */
  237. char Line1[] = "\0";
  238. char Line2[] = "\54The quick brown fox jumps over the lazy dog.";
  239. char Line3[] = "\53She sells sea shells down by the sea shore.";
  240. char Line4[] = "\0";
  241.  
  242. char FontStrikeLine[] = {32,
  243.                  0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,
  244.                 16,17,18,19,20,21,22,23,24,25,25,27,28,28,30,31,0};
  245.  
  246.  
  247. char *LineTable[] = {Line0,Line1,Line2,Line3,Line4};
  248.  
  249. char __dataBank;
  250.  
  251. ptr myApFontNamePtr;
  252.  
  253. Point CurrPos;
  254.  
  255. FontID curSysID;
  256.  
  257. FontID FontToShow;
  258.  
  259. FontID ChosenFont;
  260.  
  261. int ChosenSize;
  262.  
  263. int ChosenStyle;
  264.  
  265. int checkedID;
  266.  
  267. int MyFamSpecBits;
  268.  
  269. struct FontStatRecList{
  270.     int numFontsAvail;
  271.     int numFamsAvail;
  272.     FontStatRec FontStatRecTable[200];
  273.     } FontsAvail;
  274.  
  275. int linetodraw;                                /* shared by each window's content def proc */
  276.  
  277. GrafPortPtr CatalogWindow;                   /* current window handle  */
  278. GrafPortPtr StrikeWindow;                    /* current window handle  */
  279.  
  280.  
  281. /* ************************************************************************* */
  282. /* Our sample programs use menus that start at 250. The Edit menu items are  */
  283. /* entered first to conform to the menu manager documentation. The About     */
  284. /* and Quit menu items use IDs 256 and 257 as a convention.                     */
  285. /*                                                                             */
  286. /* ************************************************************************* */
  287.  
  288. int numFontMenuItems; /* set to number of items in font menu, after FixFontMenu is called */
  289.  
  290.  
  291. /* ************************************************************************* */
  292. /*                                                                             */
  293. /* This is the core of the program. It simply calls all the other routines   */
  294. /* in order.                                                                 */
  295. /*                                                                             */
  296. /* ************************************************************************* */
  297.  
  298. main()
  299. {
  300.     /* Startup the tools using the new toolbox call */
  301.     MyID = MMStartUp();
  302.     initRef = StartUpTools(MyID, refIsResource, 0x0001L);
  303.  
  304.     initPtrCheck(_ownerid);
  305.  
  306.     ApErrorCheck(TLStartErr);    /* Is StartUpTools OK? */
  307.     if (!_toolErr) {
  308.         InitApp();                /* initialize application specific stuff */
  309.         EventLoop();            /* do your stuff */
  310.     }
  311.     ShutDownTools(refIsHandle, initRef);    /* Let the toolbox shutdown the tools. */
  312.  
  313.     closePtrCheck();
  314. }
  315.  
  316.  
  317. /* ********************************************************************************* */
  318. /*                                                                                      */
  319. /* Assembly Procedure SaveDB:                                                         */
  320. /*                                                                                      */
  321. /* Decsription: saves data bank register and changes to data bank for globals          */
  322. /*                                                                                      */
  323. /* Inputs:     none                                                                       */
  324. /*                                                                                      */
  325. /* Outputs: data bank register contents                                                 */
  326. /*                                                                                      */
  327. /* ********************************************************************************* */
  328.  
  329. asm(SaveDB) {
  330.              phb
  331.              lda  #^__dataBank   ; high word of anything in ~globals will do
  332.              pha
  333.              plb
  334.              pla
  335.  
  336.              rtl
  337. }
  338.  
  339. /* ********************************************************************************* */
  340. /*                                                                                      */
  341. /* Assembly Procedure RestoreDB:                                                     */
  342. /*                                                                                      */
  343. /* Decsription: restores data bank register                                              */
  344. /*                                                                                      */
  345. /* Inputs:     integer value to set data bank register to                                   */
  346. /*                                                                                      */
  347. /* Outputs: changed data bank register                                                 */
  348. /*                                                                                      */
  349. /* ********************************************************************************* */
  350.  
  351. asm(RestoreDB) {
  352.              lda  4,s
  353.              pha
  354.              plb
  355.              plb
  356.              rtl
  357. }
  358.  
  359. /* ********************************************************************************* */
  360. /*                                                                                      */
  361. /* Procedure CalcLineHeight:                                                         */
  362. /*                                                                                      */
  363. /* Decsription: calculates heigth of the text line(s) to be drawn                      */
  364. /*                                                                                      */
  365. /* Inputs:     none                                                                       */
  366. /*                                                                                      */
  367. /* Outputs: heigth of the line(s) to be drawn                                         */
  368. /*                                                                                      */
  369. /* ********************************************************************************* */
  370.  
  371. CalcLineHeight()
  372. {
  373.     FontInfoRecord CurrFont;
  374.     int LineHeight;
  375.     
  376.     zapLocals();
  377.  
  378.     GetFontInfo(&CurrFont);                                    /* prepare to compute height using */
  379.                                                             /* QuickDraw II GetFontInfo call */
  380.                                                             /* i.e. # pixels between lines drawn */
  381.     LineHeight = CurrFont.ascent + CurrFont.descent + CurrFont.leading;
  382.     return(LineHeight);
  383. }
  384.  
  385.  
  386. /* ********************************************************************************* */
  387. /*                                                                                      */
  388. /* Procedure ShowFont:                                                                 */
  389. /*                                                                                      */
  390. /* Decsription: displays fontstrike, excerpted from HodgePodge example program         */
  391. /*                                                                                      */
  392. /* Inputs:     pointer to fontID                                                           */
  393. /*                                                                                      */
  394. /* Outputs: none                                                                     */
  395. /*                                                                                      */
  396. /* ********************************************************************************* */
  397.  
  398. ShowFont(fontId)
  399. FontID fontId;
  400. {
  401.  
  402. #define columnone         4
  403.  
  404.     int stringpos;                                            /* loops through ASCII values     */
  405.    
  406.     zapLocals();
  407.  
  408.     InstallFont(fontId.fidLong, ScalingOn);                /* Install with scaling enabled */
  409.     ApErrorCheck(ShowFontInstallFontErr);                    /* Is InstallFont OK? */
  410.     CurrHeight = CalcLineHeight();                            /* calculate # pixels between lines */
  411.  
  412.     GetFamInfo(fontId.fidRec.famNum, Line0);                  /* set up font name, ignore result */
  413.     Int2Dec(fontId.fidRec.fontSize,                          /* set up font size after font name */
  414.                (Line0)+Line0[0]+1,                           /* pointer to end */
  415.                4,                                             /* length of result */
  416.                0);                                             /* not signed */
  417.     Line0[0] +=4;                                           /* new length */
  418.     linetodraw = linetodraw + 15;
  419.    
  420.     for (LineCounter = 0;LineCounter < NumExampleLines;LineCounter++) {
  421.         linetodraw = linetodraw + CurrHeight;
  422.         MoveTo(columnone,linetodraw);                        /* move to beginning of line to draw */
  423.         DrawString(LineTable[LineCounter]);
  424.     }
  425.     for (LineCounter = 0;LineCounter < NumStrikeLines;LineCounter++) {
  426.         linetodraw = linetodraw + CurrHeight;
  427.         MoveTo(columnone,linetodraw);                        /* set position to Draw */
  428.         for (stringpos = 1;stringpos < 33;stringpos++) {
  429.             FontStrikeLine[stringpos] = (char) (LineCounter*32+stringpos-1);
  430.         }
  431.         DrawString(FontStrikeLine);
  432.     }
  433.     linetodraw = 0;
  434.     MoveTo(columnone,0);
  435. }
  436.  
  437.  
  438. /* ********************************************************************************* */
  439. /*                                                                                      */
  440. /* Procedure DrawCatInt2Base:                                                         */
  441. /*                                                                                      */
  442. /* Decsription: displays number and string                                              */
  443. /*                                                                                      */
  444. /* Inputs:     number to draw, base of number, number of places to display              */
  445. /*            signed number indicator, append string                                      */
  446. /*                                                                                      */
  447. /* Outputs: none                                                                     */
  448. /*                                                                                      */
  449. /* ********************************************************************************* */
  450.  
  451. DrawCatInt2Base(num,base,numplaces,signedval,catstr)
  452.  
  453. int num;                                                /* number to draw */
  454. int base;                                                /* base of number */
  455. int numplaces;                                            /* number of places to display */
  456. int signedval;                                            /* signed number indicator */
  457. char catstr[80];                                        /* append string */
  458.  
  459. {
  460.     char strtarg[80];                                    /* convert number into this string */
  461.     ptr catstrptr;                                        /* ptr to append string */
  462.     ptr strtargptr;                                        /* ptr to convert string */
  463.     
  464.     zapLocals();
  465.  
  466.     catstrptr  = catstr;                                /* set the pointers */
  467.     strtargptr = strtarg;
  468.     switch(base) {                                        /* do the conversion */
  469.         case Dec:
  470.             Int2Dec(num,strtargptr,numplaces,signedval);
  471.             break;
  472.         case Hex:
  473.             Int2Hex(num,strtargptr,numplaces);
  474.             break;
  475.         default:
  476.             /* error */
  477.             break;
  478.     }
  479.     
  480.     strtarg[numplaces]= '\0';                                /* terminate the string */
  481.     strcat(strtargptr,catstrptr);                            /* append designated string */
  482.     DrawCString(strtarg);                                    /* display result */
  483. }
  484.  
  485.  
  486. /* ********************************************************************************* */
  487. /*                                                                                      */
  488. /* Procedure MyDraw:                                                                 */
  489. /*                                                                                      */
  490. /* Decsription: window content definition procedure                                      */
  491. /*                                                                                      */
  492. /* Inputs:     none                                                                        */
  493. /*                                                                                      */
  494. /* Outputs: none                                                                     */
  495. /*                                                                                      */
  496. /* ********************************************************************************* */
  497.  
  498. MyDraw()                                                /* window content definition procedure */    
  499.  
  500. {
  501.     /* #define columnone         4 */
  502.     #define famNumbercolumn        34*6+columnone
  503.     #define fontSizecolumn        54*6+columnone
  504.     #define fontStylecolumn        68*6+columnone
  505.     char stritem1[80],stritem2[80],stritem3[80],stritem4[80];        /* string declarations */
  506.     char stritem5[80],stritem6[80],stritem7[80];
  507.     ptr strptr1,strptr2,strptr3,strptr4;                            /* string ptr declarations */
  508.     char TableTitle[80];                                            /* title string */
  509.     int eachfontavail;                                                /* index into font catalog */
  510.     int preservefontavail;                                            /* holds index temporarily */
  511.     FontStatRecPtr MyFontStatRecPtr;                                /* ptr to font status record */
  512.     FontStatRecPtr PreserveFStatRecPtr;                                /* holds ptr temporarily */
  513.     int curfamily;                                                    /* tracks font families */
  514.     int MyFamStatBits;                                                /* FamStatBits */
  515.     int dbr;                                                        /* data bank register value */
  516.     
  517.     zapLocals();
  518.  
  519.     dbr = SaveDB();                                                    /* make the data bank reg. */
  520.                                                                     /* point to globals, save it */
  521.     strptr1 = stritem1;
  522.     strptr2 = stritem2;
  523.     strptr3 = stritem3;
  524.     strptr4 = stritem4;
  525.  
  526.     strcpy(TableTitle,"\pReport of available fonts:");
  527.     LoadSysFont();                                                    /* use sys font */
  528.     ApErrorCheck(MyDrawLoadSysFontErr);                                /* Is LoadSysFont OK? */
  529.     strcpy(stritem5," fonts available, ");                            /* append strings */
  530.     strcpy(stritem6," families");
  531.     strcpy(stritem7,"");
  532.     MoveTo(columnone,50);
  533.     DrawString(TableTitle);
  534.     DrawCatInt2Base(FontsAvail.numFontsAvail,Dec,4,signednum," fonts available, ");
  535.     DrawCatInt2Base(FontsAvail.numFamsAvail,Dec,4,signednum,stritem6);
  536.     
  537.     curfamily = 0xffff;                                                /* init current family */
  538.     strcpy(stritem1," ");                                            /* init strings */
  539.     strcpy(stritem2," ");
  540.     strcpy(stritem3," ");
  541.     strcpy(stritem4," ");
  542.     eachfontavail = 0;
  543.     linetodraw = 50;
  544.     /*               012345678901234567890123456789012345678901234567890123456789012345678901234567 */
  545.     strcpy(stritem2,"Font family name                  family number       font size     font style");
  546.     linetodraw = linetodraw+30;
  547.     MoveTo(columnone,linetodraw);
  548.     DrawCString(stritem2);
  549.     do {                                                                /* loop through fonts */
  550.         MyFontStatRecPtr = &FontsAvail.FontStatRecTable[eachfontavail];    /* set pointer */
  551.         strcpy(stritem2," ");                                            /* init strings */
  552.         strcpy(stritem3," ");
  553.         strcpy(stritem4," ");
  554.         linetodraw = linetodraw+10;
  555.         if (MyFontStatRecPtr->resultID.fidRec.famNum != curfamily) {    /* next family? */
  556.                                                                         /* yes- display */
  557.             MyFamStatBits = GetFamInfo(MyFontStatRecPtr->resultID.fidRec.famNum,strptr1);
  558.             MoveTo(columnone,linetodraw);
  559.             DrawString(stritem1);
  560.             MoveTo(famNumbercolumn,linetodraw);
  561.             DrawCatInt2Base(MyFontStatRecPtr->resultID.fidRec.famNum,Hex,4,signednum,stritem7);
  562.         }
  563.                                                                        /* display size and style */
  564.         curfamily = MyFontStatRecPtr->resultID.fidRec.famNum;
  565.         MoveTo(fontSizecolumn,linetodraw);
  566.         DrawCatInt2Base(MyFontStatRecPtr->resultID.fidRec.fontSize,Dec,5,signednum,stritem7);
  567.         MoveTo(fontStylecolumn,linetodraw);
  568.         DrawCatInt2Base(MyFontStatRecPtr->resultID.fidRec.fontStyle,Dec,5,signednum,stritem7);
  569.         
  570.         ++eachfontavail;
  571.     }
  572.     while (eachfontavail < FontsAvail.numFontsAvail);
  573.     RestoreDB(dbr);                                            /* restore data bank reg. for return */
  574.                                                             /* to toolbox */
  575. }
  576.  
  577.  
  578. /* ********************************************************************************* */
  579. /*                                                                                      */
  580. /* Procedure MyDraw2:                                                                 */
  581. /*                                                                                      */
  582. /* Decsription: window content definition procedure                                      */
  583. /*                                                                                      */
  584. /* Inputs:     none                                                                        */
  585. /*                                                                                      */
  586. /* Outputs: none                                                                     */
  587. /*                                                                                      */
  588. /* ********************************************************************************* */
  589.  
  590. MyDraw2()                                                /* window content definition procedure */    
  591.  
  592. {
  593.     int dbr;                                                /* data bank register value */
  594.     
  595.     zapLocals();
  596.  
  597.     dbr = SaveDB();                                            /* make the data bank reg. */
  598.                                                             /* point to globals, save it */
  599.     linetodraw = 0;
  600.                                                             /* all families, base & non-base */
  601.     ShowFont(FontToShow.fidLong);                            /* display font strike */
  602.     LoadSysFont();
  603.     ApErrorCheck(MyDraw2LoadSysFontErr);                    /* Is LoadSysFont OK? */
  604.     RestoreDB(dbr);                                            /* restore data bank reg. for return */
  605.                                                             /* to toolbox */
  606. }
  607.  
  608.  
  609. /* ********************************************************************************* */
  610. /*                                                                                      */
  611. /* Procedure FontCheckMItem                                                             */
  612. /*                                                                                      */
  613. /* Decsription: This procedure checks specified font item in the menu bar and         */
  614. /*                unchecks previously checked item, if any                             */
  615. /*                                                                                      */
  616. /* Inputs:     pointer to FontID to be checked in menu bar,                               */
  617. /*            flag indicating whether previously checked item exists.                      */
  618. /*                                                                                      */
  619. /* Outputs: none                                                                      */
  620. /*                                                                                      */
  621. /* ********************************************************************************* */
  622.  
  623. FontCheckMItem(FontToCheck, uncheck)
  624. FontID FontToCheck;                                            /* pointer to FontID to be checked */
  625. int uncheck;                                                /* flag if prev checked item exists */
  626. {
  627.     int prevcheckedID;                                        /* menu id */
  628.     
  629.     zapLocals();
  630.  
  631.     prevcheckedID = checkedID;
  632.     if (uncheck = true) CheckMItem(false,prevcheckedID);        /* uncheck menu item */
  633.     checkedID = FamNum2ItemID(FontToCheck.fidRec.famNum);
  634.     CheckMItem(true,checkedID);                                    /* check menu item */
  635. }
  636.  
  637.  
  638. /* ********************************************************************************* */
  639. /*                                                                                      */
  640. /* Procedure AddApFont:                                                                 */
  641. /*                                                                                      */
  642. /* Decsription: copies system font into application created font,                      */
  643. /*                generates unique name and number of font family                         */
  644. /*                                                                                      */
  645. /* Inputs:     none                                                                        */
  646. /*                                                                                      */
  647. /* Outputs: none                                                                     */
  648. /*                                                                                      */
  649. /* ********************************************************************************* */
  650.  
  651. AddApFont()
  652. {
  653.     #define FontFamNameOverflow 27    
  654.     #define UnusedFontFamNum 0x80
  655.     FontID MyFont;                                            /* fontIDs proper and long form */
  656.     char stritem1[27],stritem2[27];                            /* misc. strings and ptrs to strings */
  657.     ptr strptr1,strptr2;
  658.     char myApFontName[27],fontname[80];                        /* Font name strings */
  659.     ptr fontnameptr;                                        /* ptr to Font name string */
  660.     FontHndl MyApFontHndl,MySysFontHandle;                    /* Handles to font */
  661.     int *MyApFontPatchPtr;                                    /* ptr into font */
  662.     long MyApFontSize;                                        /* size of font */
  663.     int MyFontSpecBits,MyFamStatBits,MyFamSpecBits;            /* misc. Font Bits */
  664.     int MyApFamNum;                                            /* font family number */
  665.     int nthfontname,numsuffixplaces,numleadingspaces;        /* used to create unique font name */
  666.     FontStatRec MyFontStatRec;                                /* Font status record and StatRecPtr */
  667.     FontStatRecPtr MyFontStatRecPtr;
  668.  
  669.     zapLocals();
  670.  
  671.     strptr1 = stritem1;
  672.     strptr2 = stritem2;
  673.  
  674.     strcpy(stritem1,"                          ");
  675.     strcpy(myApFontName,"ApFont");
  676.     
  677.     MyFont.fidLong = FMGetCurFID();                            /* install 16 point version of font */
  678.     
  679.     MyFont.fidRec.fontSize = 16;
  680.     InstallFont(MyFont.fidLong, ScalingOn);                    /* install */
  681.     ApErrorCheck(ApFontInstallFontErr1);                    /* Is InstallFont OK? */
  682.     
  683.     MySysFontHandle = GetFont();                            /* prepare to duplicate the font */
  684.     MyApFontSize = GetHandleSize(MySysFontHandle);            /* determine size of font */
  685.                                                             /* make room for duplicate */
  686.     MyApFontHndl = (FontHndl) NewHandle(MyApFontSize,MyID,0,0L);    /* make room for duplicate */
  687.     HLock(MyApFontHndl);
  688.     ApErrorCheck(ApFontNewHandleErr);                        /* Is NewHandle OK? */
  689.     
  690.     if (!_toolErr) {
  691.     
  692.         HandToHand(MySysFontHandle,(Handle) MyApFontHndl,MyApFontSize);
  693.         MyApFamNum = 0xfffe;                    /* prepare to validate font number not used */
  694.  
  695.         while (!(GetFamInfo(MyApFamNum,strptr1) & notFoundBit)) --MyApFamNum;
  696.  
  697.         myApFontNamePtr = myApFontName;            /* prepare to validate font name not used */
  698.         strcpy(stritem1,myApFontName);            /* init temp font name */ 
  699.         nthfontname = 0;                        /* may be used to suffix font name */
  700.                                                 /* loop until illegal or exhausted */
  701.  
  702.         while (
  703.             (GetFamNum(strptr1) != IllegalFontFamNum) && (strlen(stritem1) != FontFamNameOverflow)
  704.         ) {
  705.             ++nthfontname;                                    /* bump the suffix value */
  706.             numsuffixplaces = (int) log10(nthfontname) + 1;    /* calc # digits in suffix */
  707.                                                             /* make a string of suffix */
  708.             Int2Dec(nthfontname,strptr2,numsuffixplaces,true);
  709.             stritem2[numsuffixplaces]= '\0';                /* terminate suffix string */
  710.             strcpy(stritem1,myApFontName);                    /* reinit temp font name */
  711.             strcat(strptr1,strptr2);                        /* append suffix */
  712.         }
  713.  
  714.         c2pstr(myApFontNamePtr);
  715.         AddFamily(MyApFamNum,myApFontNamePtr);
  716.         ApErrorCheck(ApFontAddFamilyErr);                        /* Is AddFamily OK? */
  717.  
  718.                                                 /* patch the font # of the font record */
  719.         MyApFontPatchPtr =  (int *) (((char *) *MyApFontHndl) + 2);
  720.         *MyApFontPatchPtr = MyApFamNum;
  721.         AddFontVar(MyApFontHndl,0);
  722.         ApErrorCheck(ApFontAddFontVarErr);                        /* Is AddFontVar OK? */
  723.         HUnlock(MyApFontHndl);
  724.         MyFont.fidRec.famNum = MyApFamNum;
  725.         InstallFont(MyFont.fidLong, ScalingOn);
  726.         ApErrorCheck(ApFontInstallFontErr2);    /* Is InstallFont OK? */
  727.     }
  728. }
  729.  
  730.  
  731. /* ********************************************************************************* */
  732. /*                                                                                      */
  733. /* Procedure InventoryFonts:                                                         */
  734. /*                                                                                      */
  735. /* Decsription: produces font catalog consisting of number of families                   */
  736. /*                (base & non-base), generates unique name and number of font family.     */
  737. /*                assumes LoadFont and FindFontStats group fonts by size in increasing */
  738. /*                order within each family and by style in increasing order within     */
  739. /*                each size. If fonts are to be loaded, they are also set to be          */
  740. /*                purgeable.                                                               */
  741. /*                                                                                      */
  742. /* Inputs:     flag whether to load fonts as they are being inventoried                 */
  743. /*                                                                                      */
  744. /* Outputs: none                                                                     */
  745. /*                                                                                      */
  746. /* ********************************************************************************* */
  747.  
  748. InventoryFonts(loadthefonts)
  749. int loadthefonts;
  750.  
  751. {
  752.     FontID SelectFontID;                            /* fontIDs proper and long form */
  753.     char stritem1[27],stritem2[27];                    /* misc. strings and ptrs to strings */
  754.     ptr strptr1,strptr2;
  755.     char fontname[80];
  756.     ptr fontnameptr;
  757.                                                             /* used to loop through fonts*/
  758.     int eachfamavail,numfontsinfam,eachfontinfam,eachfontavail;
  759.     int cursize,numsizesinfont,numstylesinsize;                /* used to loop through fonts */
  760.                                                             /* misc. font values*/
  761.     int MyFontSpecBits,MyOtherFontSpecBits,MyFamStatBits,MyFamSpecBits; 
  762.     FontStatRec MyFontStatRec;                                /* Font status record and StatRecPtr */
  763.     FontStatRecPtr MyFontStatRecPtr;
  764.  
  765.     zapLocals();
  766.  
  767.     strptr1 = stritem1;
  768.     strptr2 = stritem2;
  769.     
  770.     LoadSysFont();
  771.     ApErrorCheck(InvFontLoadSysFontErr);                        /* Is LoadSysFont OK? */
  772.     
  773.     MyFamSpecBits = 0;
  774.     FontsAvail.numFamsAvail = CountFamilies(MyFamSpecBits);        /* determine no. of families */
  775.     MyFontSpecBits = realOnlyBit | anyFamBit | anyStyleBit | anySizeBit;   /* all real fonts */
  776.     SelectFontID.fidRec.famNum = 0;
  777.     SelectFontID.fidRec.fontStyle = 0xff;                                /* (any style) */
  778.     SelectFontID.fidRec.fontSize = 1;
  779.     FontsAvail.numFontsAvail = CountFonts(SelectFontID.fidLong, MyFontSpecBits);
  780.                                                                 /* determine # of fonts */
  781.  
  782.     eachfamavail = 0;                                            /* init family counter */
  783.     eachfontavail = 0;                                            /* init font counter */
  784.     fontnameptr = fontname;                                        /* set up ptr to font name string*/
  785.     MyFontSpecBits = realOnlyBit | anyStyleBit | anySizeBit;    /* all real fonts in each family */
  786.  
  787.     do {                                            /*loop through font family list */
  788.         ++eachfamavail;                                /* increment family counter */
  789.  
  790.                                                     /* determine number of nth family */
  791.         SelectFontID.fidRec.famNum = FindFamily(MyFamSpecBits,eachfamavail,fontnameptr);
  792.  
  793.         numfontsinfam = CountFonts(SelectFontID.fidLong, MyFontSpecBits);
  794.                                                     /* determine # fonts in that family */
  795.  
  796.         eachfontinfam = 0;                            /* init fonts in family counter */
  797.         numsizesinfont = 0;                            /* init sizes in family counter */
  798.         cursize = 0;                                /* init current size */
  799.  
  800.         do {                                        /* loop through the fonts in this family */
  801.             ++eachfontinfam;                    /* increment fonts in family counter */
  802.  
  803.                                                 /* set pointer to nth font status record */
  804.             MyFontStatRecPtr = &FontsAvail.FontStatRecTable[eachfontavail];
  805.  
  806.             switch(loadthefonts) {
  807.                 case loadfonts:
  808.                     /* assume LoadFont and FindFontStats group fonts by size in increasing */
  809.                     /* order within each family and by style in increasing order within     */
  810.                     /* each size */
  811.  
  812.                     /* there was a bug in the status record returned by LoadFont prior to */
  813.                     /* GS/OS, substitute FindFontStats,InstallFont */
  814.                     /* in place of LoadFont if and when running under pre-GS/OS system */
  815.                     /* to return correct status record */
  816.  
  817.                     /* make current and */
  818.                     /* determine stats of nth font in family */
  819.                     LoadFont(SelectFontID.fidLong, MyFontSpecBits,eachfontinfam,MyFontStatRecPtr);
  820.                     ApErrorCheck(InvFontLoadFontErr);    /* Is InstallFont OK? */
  821.  
  822.                     /* prepare to set purge bit, at discretion of application */
  823.                     /* check first that not attempting to set purge bit of system font */
  824.                     if (MyFontStatRecPtr->resultID.fidLong != curSysID.fidLong)
  825.                         MyFontStatRecPtr->resultStats = 
  826.                             MyFontStatRecPtr->resultStats | purgeBit;
  827.  
  828.                     /* set purge bit */
  829.                     /* !!!! */
  830.                     /* When fonts are to be marked purgeable using SetPurgeStat, the id of */
  831.                     /* the font to purge should be that returned from a font manager call, */
  832.                     /* such as FMGetCurFID, FindFontStats, or LoadFont. */
  833.  
  834.                     SetPurgeStat(MyFontStatRecPtr->resultID,MyFontStatRecPtr->resultStats);
  835.  
  836.                                                     /* Is SetPurgeStat OK? */
  837.                     ApErrorCheck(InvFontSetPurgeStatErr);
  838.                     break;
  839.                 
  840.                 case dontloadfonts:
  841.                                                     /* determine stats of nth font in family */
  842.                     FindFontStats(SelectFontID.fidLong, MyFontSpecBits,
  843.                                   eachfontinfam, MyFontStatRecPtr);
  844.                     break;
  845.                     
  846.                 default:
  847.                     /*error */
  848.                     break;
  849.             }
  850.                 
  851.                                             /* does the font size equal previous font? */
  852.             if (MyFontStatRecPtr->resultID.fidRec.fontSize != cursize)
  853.             {
  854.                 ++numsizesinfont;            /* no- then increment number of sizes/family*/
  855.                 numstylesinsize = 0;        /*     and set to zero number of styles/size*/
  856.             }
  857.                                             /* store current font size for comparison */
  858.             cursize = MyFontStatRecPtr->resultID.fidRec.fontSize;
  859.             ++numstylesinsize;                /* increment number of styles/size */
  860.             ++eachfontavail;                /* increment fonts counter */
  861.         }
  862.         while (eachfontinfam < numfontsinfam);
  863.     }
  864.     while (eachfamavail < FontsAvail.numFamsAvail);
  865. }
  866.  
  867.  
  868. /* ********************************************************************************* */
  869. /*                                                                                      */
  870. /* Procedure FindAltSysFont                                                             */
  871. /*                                                                                      */
  872. /* Decsription: resets system font to first other font cataloged with same size         */
  873. /*                                                                                      */
  874. /* Inputs:     none                                                                     */
  875. /*                                                                                      */
  876. /* Outputs: none                                                                      */
  877. /*                                                                                      */
  878. /* ********************************************************************************* */
  879.  
  880. FindAltSysFont()
  881. {
  882.     int cursize,eachfontavail;                /* loop variables */
  883.     FontStatRecPtr MyFontStatRecPtr;        /* points to font status record */
  884.     
  885.     zapLocals();
  886.  
  887.     cursize = curSysID.fidRec.fontSize;
  888.     eachfontavail = 0;                            /* init font counter */
  889.     do {                                        /* loop through the font catalog */
  890.                                                 /* set pointer to nth font status record */
  891.         MyFontStatRecPtr = &FontsAvail.FontStatRecTable[eachfontavail];
  892.         ++eachfontavail;
  893.     }
  894.     while ((eachfontavail<FontsAvail.numFontsAvail) && 
  895.         ((MyFontStatRecPtr->resultID.fidRec.fontSize != cursize) || 
  896.          (MyFontStatRecPtr->resultID.fidLong == curSysID.fidLong)));
  897.  
  898.                                         /* change system font if found other font of same size */
  899.     if ((MyFontStatRecPtr->resultID.fidLong != curSysID.fidLong) &&
  900.         (MyFontStatRecPtr->resultID.fidRec.fontSize == cursize)) {
  901.         FMSetSysFont(MyFontStatRecPtr->resultID);
  902.                                                 /* Is FMSetSysFontErr OK? */
  903.         ApErrorCheck(FindAltSysFontFMSetSysFontErr);
  904.         curSysID.fidLong = FMGetSysFID();
  905.     }
  906. }
  907.  
  908.  
  909. /* ********************************************************************************* */
  910. /*                                                                                      */
  911. /* Procedure DispNewFont:                                                              */
  912. /*                                                                                      */
  913. /* Decsription: resizes window data and forces redisplay of window contents          */
  914. /*                                                                                      */
  915. /* Inputs:     none                                                                     */
  916. /*                                                                                      */
  917. /* Outputs: none                                                                     */
  918. /*                                                                                      */
  919. /* ********************************************************************************* */
  920.  
  921. DispNewFont()
  922. {
  923.     int drawheight;
  924.  
  925.     zapLocals();
  926.  
  927.     InstallFont(FontToShow.fidLong, ScalingOn);
  928.     ApErrorCheck(DispNewFontInstallFontErr);                    /* Is InstallFont OK? */
  929.     CurrHeight = CalcLineHeight();                                /* calc # pixels between lines */
  930.     drawheight = 40 + (13*CurrHeight) + 20;
  931.     SetDataSize(ScreenWidth,drawheight,StrikeWindow);
  932.     SetPort(StrikeWindow);                                        /* insure correct port */
  933.     EraseRect(&(*StrikeWindow).portRect);                        /* erase the port */
  934.     InvalRect(&(*StrikeWindow).portRect);                        /* and cause it to be redrawn */
  935. }
  936.  
  937.  
  938. /* ********************************************************************************* */
  939. /*                                                                                      */
  940. /* Procedure MenuFontSelect:                                                         */
  941. /*                                                                                      */
  942. /* Decsription: checks the item in menu bar and initiates display of font strike      */
  943. /*                                                                                      */
  944. /* Inputs:     user selected font menu item                                             */
  945. /*                                                                                      */
  946. /* Outputs: none                                                                     */
  947. /*                                                                                      */
  948. /* ********************************************************************************* */
  949.  
  950. MenuFontSelect()
  951. {
  952.     int theMenuID;                                    /* gets user selected font menu item */
  953.     
  954.     zapLocals();
  955.  
  956.     theMenuID = (int) (EventRec.wmTaskData);                /* pick up menuID */
  957.                                                             /* determine font ID */
  958.     FontToShow.fidRec.famNum = ItemID2FamNum(theMenuID);    /* determine family # */
  959.     FontToShow.fidRec.fontSize = ChosenSize;                /* set pt. font */
  960.     FontToShow.fidRec.fontStyle = ChosenStyle;                /* set style    */
  961.     FontCheckMItem(FontToShow.fidLong, douncheck);            /* check font in menu */
  962.     DispNewFont();                                            /* display font strike */                                                        
  963. }
  964.  
  965.  
  966. /* ********************************************************************************* */
  967. /*                                                                                      */
  968. /* Procedure MenuFontChoose:                                                         */
  969. /*                                                                                      */
  970. /* Decsription:    Invokes choose font dialog, checks the user specified item in          */
  971. /*                menu bar, and initiates display of font strike                          */
  972. /*                                                                                      */
  973. /* Inputs:     user selection of 'choose' from font menu                                 */
  974. /*                                                                                      */
  975. /* Outputs: none                                                                     */
  976. /*                                                                                      */
  977. /* ********************************************************************************* */
  978.  
  979. MenuFontChoose()
  980. {
  981.     GrafPortPtr preserveport;
  982.  
  983.     zapLocals();
  984.  
  985.     preserveport = GetPort();
  986.     SetPort(StrikeWindow);                                    /* operate on strike port */
  987.     
  988.     ChosenFont.fidLong = ChooseFont(FontToShow.fidLong, 0);    /* user font choice */
  989.     ApErrorCheck(MenuFontChooseErr);                        /* Is ChooseFont OK? */
  990.     if (ChosenFont.fidLong) {
  991.         FontToShow.fidLong = ChosenFont.fidLong;
  992.         ChosenSize = FontToShow.fidRec.fontSize;            /* store font size chosen */
  993.         ChosenStyle = FontToShow.fidRec.fontStyle;            /* store font style chosen */
  994.         FontCheckMItem(FontToShow.fidLong, douncheck);        /* check font in menu */
  995.         DispNewFont();                                        /* display font strike */                                
  996.     }
  997.     
  998.     SetPort(preserveport);                                    /* restore port */
  999. }
  1000.  
  1001.  
  1002. /* ************************************************************************* */
  1003. /*                                                                             */
  1004. /* Procedure OpenCatalogWindow                                                  */
  1005. /*                                                                             */
  1006. /* Decsription:    This routine creates and shows the catalog window and         */
  1007. /*                disables the menu item for opening the catalog window         */
  1008. /*                                                                             */
  1009. /* ************************************************************************* */
  1010.  
  1011. OpenCatalogWindow()
  1012. {
  1013.     CatalogWindow = NewWindow2(NULL, NULL, MyDraw, NULL, 2,
  1014.         CatalogWindowID, rWindParam1);                                 /* create and show window */
  1015.     SetPort(CatalogWindow);
  1016.     ShowWindow(CatalogWindow);
  1017.     DisableMItem(OpenCatWindowID);                                    /* disable menu item */
  1018. }
  1019.  
  1020.  
  1021. /* ************************************************************************* */
  1022. /*                                                                             */
  1023. /* Procedure OpenStrikeWindow                                                  */
  1024. /*                                                                             */
  1025. /* Decsription:    This routine creates and shows the font strike  window and     */
  1026. /*                disables the menu item for opening the font strike window     */
  1027. /*                                                                             */
  1028. /* ************************************************************************* */
  1029.  
  1030. OpenStrikeWindow()
  1031. {
  1032.     StrikeWindow = NewWindow2(NULL, NULL, MyDraw2, NULL, 2,
  1033.         StrikeWindowID, rWindParam1);                                /* create and show window */
  1034.     SetPort(StrikeWindow);
  1035.     ShowWindow(StrikeWindow);
  1036.     SetMenuFlag(enableMenu,FontMenuID);                                /* enable the font menu */
  1037.     HiliteMenu(FALSE,FontMenuID);                                    /* force it (only) to redraw */
  1038.     DisableMItem(OpenStrikeWindowID);                                /* disable menu item */
  1039. }
  1040.  
  1041.  
  1042. /* ************************************************************************* */
  1043. /*                                                                             */
  1044. /* InitApp - This routine is called once after the tools are started. This   */
  1045. /* is where you would create your menus, and other objects your program will */
  1046. /* need at the very start.                                                     */
  1047. /*                                                                             */
  1048. /* ************************************************************************* */
  1049.  
  1050. InitApp()
  1051. {
  1052.     int menuheight;                                    /* height of menu bar */
  1053.     int maxfontmitems;                                /* max # of fonts to list in menu */
  1054.     int menuversioncheck;                            /* menu version less prototype bit */
  1055.     int i;                                            /* loop variable */
  1056.  
  1057.     zapLocals();
  1058.  
  1059.     WaitCursor();                                            /* inventory make take a while */
  1060.     ShowCursor();
  1061.     QuitFlag = 0;
  1062.     curSysID.fidLong = FMGetSysFID();                        /* find and store the system fontID */
  1063.     AddApFont();
  1064.     InventoryFonts(loadfonts);
  1065.     FindAltSysFont();                                          /* make sys font any other 8 pt. font*/
  1066.     SetSysBar(NewMenuBar2(refIsResource, 0x0001L, NULL));
  1067.     SetMenuBar(NULL);
  1068.     
  1069.     FixAppleMenu(AppleMenuID);                              /* Add DAs to apple menu     */
  1070.     MyFamSpecBits = 0;
  1071.                                                             /* append fonts to menu if */
  1072.                                                             /* they'll fit, assume sys font */
  1073.                                                             /* is 8 pt. font */
  1074.     menuheight = FixMenuBar();
  1075.     maxfontmitems = (int) ((200 - 2*menuheight) / menuheight);    
  1076.     menuversioncheck = MenuVersion() & 0x7fff;                        /* strip the prototype bit */
  1077.     if ((FontsAvail.numFamsAvail <= maxfontmitems) || menuversioncheck >= 0x300)
  1078.         FixFontMenu(FontMenuID,ChooseID+1,MyFamSpecBits);            /* put fonts in font menu */
  1079.     CalcMenuSize(0,0,FontMenuID);                                    /* reset size of font menu */
  1080.     numFontMenuItems = CountMItems(FontMenuID);                        /* used to handle font menu */
  1081.                                                                     /* choices in DoMenuSelect */
  1082.     FontToShow.fidLong = FMGetSysFID();                                /* get system font id */
  1083.     FontCheckMItem(FontToShow.fidLong, omituncheck);                /* check font in menu */                        
  1084.     ChosenSize = FontToShow.fidRec.fontSize;                        /* store font size chosen */
  1085.     ChosenStyle = FontToShow.fidRec.fontStyle;                        /* store font style chosen */
  1086.  
  1087.     DrawMenuBar();
  1088.     
  1089.     OpenCatalogWindow();                                    /* create and show windows, */
  1090.     OpenStrikeWindow();                                        /* disable open window menu choices */
  1091.     SetPort(CatalogWindow);
  1092.     DispNewFont();                                            /* display font strike */                                                    
  1093.     
  1094.     InitCursor();                                            /* restore cursor to normal */
  1095. }
  1096.  
  1097.  
  1098. /* ************************************************************************* */
  1099. /*                                                                             */
  1100. /* InGoAway - This routine gets called when the user clicks in the go away   */
  1101. /* box of a window.                                                          */
  1102. /*                                                                             */
  1103. /* ************************************************************************* */
  1104.  
  1105. InGoAway()
  1106. {
  1107.     GrafPortPtr windowtoclose;
  1108.  
  1109.     zapLocals();
  1110.  
  1111.     windowtoclose = (GrafPortPtr) EventRec.wmTaskData;            /* close the window  */
  1112.     CloseWindow(windowtoclose);
  1113.     if (windowtoclose == CatalogWindow)                         /* enable open window menu opt. */
  1114.         EnableMItem(OpenCatWindowID);
  1115.     else if (windowtoclose == StrikeWindow) {
  1116.         SetMenuFlag(disableMenu,FontMenuID);                    /* disable the font menu */
  1117.         HiliteMenu(FALSE,FontMenuID);                            /* force it (only) to redraw */
  1118.         EnableMItem(OpenStrikeWindowID);
  1119.     }
  1120. }
  1121.  
  1122.  
  1123. /* ************************************************************************* */
  1124. /*                                                                             */
  1125. /* Ignore - called when an event occurs that you don't want/need to handle   */
  1126. /*                                                                             */
  1127. /* ************************************************************************* */
  1128.  
  1129. Ignore()
  1130. {
  1131.     /* Does nothing */
  1132. }
  1133.  
  1134.  
  1135. /* ************************************************************************* */
  1136. /*                                                                             */
  1137. /* DoAbout - Show the vanity box until the OK button is hit. Calls             */
  1138. /* NoteAlert to display a dialog box with an icon and handle mouse clicks.   */
  1139. /*                                                                             */
  1140. /* ************************************************************************* */
  1141.  
  1142. DoAbout()
  1143. {
  1144.     AlertWindow(4,NULL, 0x0001L);
  1145. }
  1146.  
  1147.  
  1148. /* ************************************************************************* */
  1149. /*                                                                             */
  1150. /* DoUpdate - This routine is called if you have a window and the Event         */
  1151. /* Manager notices that it needs to have some or all of it redrawn.             */
  1152. /*                                                                             */
  1153. /* ************************************************************************* */
  1154.  
  1155. DoUpdate()
  1156.     /* no update */
  1157.  
  1158.  
  1159. /* ************************************************************************* */
  1160. /*                                                                             */
  1161. /* DoQuit - Set the quit flag. This tells the Event loop to exit.             */
  1162. /*                                                                             */
  1163. /* ************************************************************************* */
  1164.  
  1165. DoQuit()
  1166. {
  1167.     QuitFlag = -1;
  1168. }
  1169.  
  1170.  
  1171. DoMenuSelect()
  1172. {
  1173.     /* Procedure to handle all menu selections.  Examines the event.TaskData
  1174.     ** menu item ID word from TaskMaster (from Event Manager) and calls the
  1175.     ** appropriate routine.  While the routine is running the menu title is
  1176.     ** still highlighted.  After the routine returns, we unhilight the
  1177.     ** menu title.
  1178.     */
  1179.     
  1180.     unsigned int    menuNum, itemNum;
  1181.  
  1182.     zapLocals();
  1183.  
  1184.     menuNum = HiWord(EventRec.wmTaskData);
  1185.     itemNum = LoWord(EventRec.wmTaskData);
  1186.  
  1187.                                                                     /* font menu font selection? */
  1188.     if ((itemNum > ChooseID) && (itemNum <= (ChooseID+numFontMenuItems)))
  1189.         MenuFontSelect();                                            /* yes- call this routine */
  1190.     else {
  1191.         switch (itemNum) {
  1192.             case AboutID:
  1193.                 DoAbout();
  1194.                 break;
  1195.             case OpenCatWindowID:
  1196.                 OpenCatalogWindow();
  1197.                 break;
  1198.             case OpenStrikeWindowID:
  1199.                 OpenStrikeWindow();
  1200.                 break;
  1201.             case QuitID:
  1202.                 DoQuit();
  1203.                 break;
  1204.             case ChooseID:
  1205.                 MenuFontChoose();
  1206.                 break;
  1207.         }
  1208.     }
  1209.     HiliteMenu(0, menuNum);     /* Unhighlight the menu title. */
  1210. }
  1211.  
  1212.  
  1213.  
  1214. /* ************************************************************************* */
  1215. /*                                                                             */
  1216. /* EventLoop - This routine is the heart of your application. It is repeat-  */
  1217. /* edly called and when the user selects/operates something, it dispatches   */
  1218. /* to a routine to do the proper thing.                                         */
  1219. /*                                                                             */
  1220. /* ************************************************************************* */
  1221.  
  1222. EventLoop()
  1223. {
  1224.     word theTask;
  1225.     
  1226.     zapLocals();
  1227.  
  1228.     do {
  1229.         theTask = TaskMaster(everyEvent,&EventRec);    /* Get an event from TaskMaster */
  1230.         switch (theTask) {                            /* switch on the event type. */
  1231.             case updateEvt:                            /* Handle updates. */
  1232.                 DoUpdate();
  1233.                 break; 
  1234.             case wInMenuBar:                        /* Handle selections in Special */
  1235.             case wInSpecial:                        /* and normal menu item selects */
  1236.                 DoMenuSelect();
  1237.                 break;
  1238.             case wInGoAway:                            /* Handle a click in the go away box */
  1239.                 InGoAway();
  1240.                 break;
  1241.         }
  1242.     } while (!QuitFlag);                            /* Loop until "Quit" is selected */
  1243. }
  1244.  
  1245.